package sysinit

import (
	"github.com/gin-gonic/gin"
	swaggerFiles "github.com/swaggo/files"
	ginSwagger "github.com/swaggo/gin-swagger"

	_ "gitee.com/hwpro/cvecompetition/docs"
	"gitee.com/hwpro/cvecompetition/global"
	"gitee.com/hwpro/cvecompetition/middleware"
	"gitee.com/hwpro/cvecompetition/router"
)

func InitRouter() *gin.Engine {
	var ginRouter = gin.Default()
	if global.GmsConfig.System.Env == "dev" {
		gin.SetMode(gin.DebugMode)
	} else {
		gin.SetMode(gin.ReleaseMode)
	}
	ginRouter.NoRoute(func(c *gin.Context) {
		global.NotFoundError(c)
	})
	// setting middleware
	// cross domain
	ginRouter.Use(middleware.CrossDomain())
	//setting swagger doc address
	ginRouter.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
	//router group
	apiGroup := ginRouter.Group("/v1")
	// all module api register
	router.NewRegisterHelper().Init(apiGroup).Add(&router.Welcome{}).RunRegister()
	return ginRouter
}
